package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;

    /**
     * TODO
     *      - 查询文章
     *      - uri: /api/v1/news/list
     *      - method: POST
     * @param dto   WmNewsPageReqDto
     * @return      ResponseResult
     */
    @PostMapping("/list")
    public ResponseResult findAll(@RequestBody WmNewsPageReqDto dto){
        return  wmNewsService.findAll(dto);
    }

    /**
     * TODO
     *      - 发布文章
     *      - uri: /api/v1/news/submit
     *      - method: POST
     * @param dto   WmNewsPageReqDto
     * @return      ResponseResult
     */
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto) {
        return wmNewsService.submit(dto);
    }

    /**
     * TODO
     *      - 根据id查询文章
     *      - uri: /api/v1/news/one/{id}
     *      - method: get
     * @param id   id
     * @return      ResponseResult
     */
    @GetMapping("/one/{id}")
    public ResponseResult one(@PathVariable Integer id) {
        return wmNewsService.one(id);
    }

    /**
     * TODO
     *      - 根据id删除文章
     *      - uri: /api/v1/news/del_news/{id}
     *      - method: get
     * @param id   id
     * @return      ResponseResult
     */
    @GetMapping("/del_news/{id}")
    public ResponseResult delNews(@PathVariable Integer id) {
        return wmNewsService.delNews(id);
    }

    /**
     * TODO
     *      - 文章上下架
     *      - uri: /api/v1/news/down_or_up
     *      - method: post
     * @param dto   WmNewsDto
     * @return      ResponseResult
     */
    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto) {
        return wmNewsService.downOrUp(dto);
    }
}